﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace ArgusLib.Controls
{
	public class ToolStrip : System.Windows.Forms.ToolStrip
	{
		public ToolStrip()
			: base()
		{
			this.BackColor = Color.Black;
			if (ArgusLib.Environment.Runtime == Runtime.Mono)
			{
				this.ItemAdded += ToolStrip_ItemAdded;
				this.ItemRemoved += ToolStrip_ItemRemoved;
			}
		}

		#region Mono
		void ToolStrip_ItemAdded(object sender, ToolStripItemEventArgs e)
		{
			e.Item.TextChanged += Item_Changed;
		}

		void ToolStrip_ItemRemoved(object sender, ToolStripItemEventArgs e)
		{
			e.Item.TextChanged -= Item_Changed;
		}

		void Item_Changed(object sender, EventArgs e)
		{
			if (this.AutoSize == false)
				return;

			int width = 1;
			int height = this.ClientSize.Height;
			foreach (ToolStripItem item in this.Items)
			{
				if (item.Bounds.Right > width)
					width = item.Bounds.Right;
				if (item.Width > width)
					width = item.Width;
				//if (item.Bounds.Bottom > height)
				//	height = item.Bounds.Bottom;
				//if (item.Height > height)
				//	height = item.Height;
			}
			this.ClientSize = new Size(width, height);
		}

		public new Color BackColor
		{
			get { return base.BackColor; }
			set
			{
				if (ArgusLib.Environment.Runtime == Runtime.Mono)
					return;
				base.BackColor = value;
			}
		}

		#endregion
	}
}
